<?php
class SiteTreeSorter extends DataObjectDecorator {
    public function augmentAllChildrenIncludingDeleted($stageChildren, $context) {
        if (property_exists($this->owner, "customSort") || $this->owner->hasMethod("getCustomSort")) {
            $customSort = (property_exists($this->owner, "customSort")) ? (array)$this->owner->customSort : (array)$this->owner->getCustomSort();
            $sortDir = (count($customSort) > 1) ? array_pop($customSort) : "DESC";
            $stageChildren->sort($customSort[0], $sortDir);
        }
    }
}
